<template>
  <div>
    <!--条件筛选-->
    <TopFilter
      :list="topFilterList"
      :cols="3"
      :isSubmitBtn="true"
      :collapse="boolean"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
    <!--操作 -->
    <el-button size="small" type="primary" icon="el-icon-printer" @click="saveHandle">打印预览</el-button>
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <div>
      <businessOrder :data="patternData" />
    </div>
    <BasePrint ref="print" :data="printList" template="businessOrder" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import businessOrder from './businessOrder.vue';
import { getBusinessStatement, getPrinter } from '@/api/repair/queryStatistics/queryAccounts';
import moment from 'moment';
export default {
  name: 'LHMBusinessOrder',
  components: { businessOrder },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    this.formData = null;
    return {
      topFilterList: this.createTopFilterList(),
      patternData: [],
      fetchParams: { xhrAbort: true },
      visible: false,
      visible1: false,
      boolean: false,
      isSelectColumn: false,
      printList: [],
      dialogTitle: '',
      fetchApi: getBusinessStatement,
      // columns: this.createTableCheckColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.FilterTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '日期范围',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期',
          // minDateTime: '2020-02-29',
          initialValue: [moment('2020-03-11').format('YYYY-MM-DD'), moment(new Date()).format('YYYY-MM-DD')],
          rules: [{ required: true, message: '请选日期范围', trigger: 'change' }]
        }
      ];
    },
    createTableCheckColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '类别',
          dataIndex: 'LX',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '统计期',
          dataIndex: 'TJQ_ZS',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '年累计',
          dataIndex: 'NLJ_ZS',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    tableAllData(val) {
      // this.printList = val;
    },
    selectData(val) {
      this.tableData = val;
    },
    selectChangeHandle(val) {
      this.selectedRow = val;
    },
    async changeHandle(val) {
      let begin = this.topFilterList.find(item => item.fieldName === 'beginDate|endDate').initialValue[0];
      let end = this.topFilterList.find(item => item.fieldName === 'beginDate|endDate').initialValue[1];
      let json = { beginDate: moment(begin).format('YYYY-MM-DD'), endDate: moment(end).format('YYYY-MM-DD') };
      if (begin && end) {
      } else {
        return this.$notify.warning({ title: '提示信息', message: '请选择日期范围！' });
      }
      let res = await getPrinter(json);
      this.patternData = res.data;
      for (var item in this.patternData.SXQK) {
        this.patternData.SXQK[item] = this.patternData.SXQK[item]==0?'':this.patternData.SXQK[item];
      }
      for (var item in this.patternData.YYSRQK) {
        this.patternData.YYSRQK[item] = this.patternData.YYSRQK[item]=='0.00'?'':this.patternData.YYSRQK[item];
      }
      this.patternData['unit'] = moment(begin).format('YYYY-MM-DD') + ' 至 ' + moment(end).format('YYYY-MM-DD');
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async saveHandle() {
      let begin = this.topFilterList.find(item => item.fieldName === 'beginDate|endDate').initialValue[0];
      let end = this.topFilterList.find(item => item.fieldName === 'beginDate|endDate').initialValue[1];
      console.log(begin, end, 'kkkkkk');
      if (begin && end) {
        let json = { beginDate: moment(begin).format('YYYY-MM-DD'), endDate: moment(end).format('YYYY-MM-DD') };
        let res = await getPrinter(json);
        if (res.resultCode == 200) {
          this.printList = res.data;
          for (var item in this.printList.SXQK) {
            this.printList.SXQK[item] = this.printList.SXQK[item]==0?'':this.printList.SXQK[item];
          }
          for (var item in this.printList.YYSRQK) {
            this.printList.YYSRQK[item] = this.printList.YYSRQK[item]=='0.00'?'':this.printList.YYSRQK[item];
          }
          this.printList['unit'] = moment(begin).format('YYYY-MM-DD') + ' ~ ' + moment(end).format('YYYY-MM-DD');
          console.log(this.printList, '打印数据');
          this.$refs.print.EXCUTE_PRINT();
        }
      } else {
        this.$notify.warning({ title: '提示信息', message: '请选择日期范围！' });
      }
    },
    showHandler() {
      // 显示
      this.dialogTitle = `其他费用`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
